<template>
  <div class="lay-container" :style="{ width }">
    <el-menu :default-active="route.path" router :collapse="isCollapsed">
      <!-- 添加 router 属性 -->
      <div class="school-icon">
        <img src="https://img1.baidu.com/it/u=3884491888,4260481962&fm=253&app=138&f=JPEG?w=800&h=800" alt="江财现经管">
      </div>
      <h3 v-if="!isCollapsed" class="menu-title">{{ props.title }}</h3>
      <el-menu-item
        v-for="item in menuItems"
        :key="item.path"
        :index="item.path"
        :disabled="isCollapsed">
        <el-icon>
          <component :is="item.icon" />
        </el-icon>
        <span>{{ item.title }}</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from 'vue-router'
// 引入使得侧边栏开启关闭的显示变量  为了统一管理 我使用的是pinia
import { useUIStore } from '@/stores/UI'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
const Uistore = useUIStore()
const { isCollapsed } = storeToRefs(Uistore)
const route = useRoute()
// 为了使得结构简化 这里使用数组来遍历菜单项 这里就不写下拉的 el-sub-menu了
const menuItems = [
  {
    path: '/home',
    icon: 'House',
    title: '首页'
  },
  {
    path: '/students',
    icon: 'User',
    title: '学生管理'
  },

  {
    path: '/courses',
    icon: 'Document',
    title: '课程管理'
  },
  {
    path: '/departments',
    icon: 'OfficeBuilding',
    title: '系部管理'
  },
  {
    path: '/about',
    icon: 'Share',
    title: '关于'
  },
  {
    path: '/test',
    icon: 'EditPen',
    title: '测试'
  }
]
const props = defineProps({
  title: {
    type: String,
    required: true
  }
})

// width 的动态响应
const width = computed(() => {
  return isCollapsed.value ? '64px' : '200px'
})
</script>

<style scoped lang="scss">
// 侧边栏
.lay-container {
  background: linear-gradient(135deg, #800909, #8B0000);
  border-right: 1px solid #e4e7ed;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  height: 100vh;
  top: 0;
  transition: all 0.3s ease-in-out;
  overflow: hidden;

  .el-menu {
    border: none;
    padding: 16px 0;
    background: transparent;
    transition: all 0.3s ease-in-out;

    .menu-title {
      text-align: center;
      color: #fff;
      font-size: 18px;
      font-weight: bold;
      margin: 20px 0 30px;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
      transition: all 0.3s ease-in-out;
      opacity: 1;
    }

    .el-menu-item {
      height: 48px;
      line-height: 48px;
      margin: 8px 12px;
      border-radius: 8px;
      transition: all 0.3s ease;
      color: rgba(255, 255, 255, 0.8);
      white-space: nowrap;
      overflow: hidden;

      .el-icon {
        color: rgba(255, 255, 255, 0.8);
        font-size: 18px;
        transition: all 0.3s ease;
        margin-right: 12px;
      }

      span {
        font-weight: 500;
        transition: all 0.3s ease;
        opacity: 1;
      }

      &:hover {
        background-color: rgba(255, 255, 255, 0.15);
        color: #fff;
        transform: translateX(5px);

        .el-icon {
          color: #fff;
        }
      }

      &.is-active {
        background: linear-gradient(45deg, #b85e14, #FFA500);
        color: #fff;

        .el-icon {
          color: #fff;
        }
      }
    }
  }
}
.el-menu--collapse {
    opacity: 0;
  }

  .school-icon {
    text-align: center;
    padding: 25px 0 15px;

    img {
      width: 65px;
      height: 65px;
      border-radius: 12px;
      border: 2px solid rgba(255, 215, 0, 0.4);
      transition: all 0.3s ease;
      background: rgba(255, 255, 255, 0.08);
      padding: 10px;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
      object-fit: contain;
    }

    img:hover {
      transform: scale(1.03);
      border-color: rgba(255, 215, 0, 0.6);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
      background: rgba(255, 255, 255, 0.12);
    }
  }
</style>
